<?php

namespace App\Recharge\Bean;


use App\Basic\Bean;

class RequestResultBean extends Bean
{
    const GET = 'GET';
    const POST = 'POST';

    /**
     * @var string 请求路径
     */
    public string $url;

    /**
     * @var string 请求方法
     */
    public string $method = self::POST;

    /**
     * @var array|string 请求参数 post或get
     */
    public string|array $request = [];

    /**
     * @var string|false 返回信息
     */
    public string|false $response = '';

    /**
     * @var array 格式化后的返回信息
     */
    public array $formatResponse;

    /**
     * @var array 其他的一些参数 详情查看guzzle-http
     */
    public array $options = [];

    /**
     * @var bool 请求结果
     */
    public bool $result = false;

    /**
     * @var string
     */
    public string $errorMessage = "";

    /**
     * @var bool
     */
    public bool $sendApi = false;

    /**
     * @var null|callable 接口同步结束返回处理
     */
    public $apiSynchronousEndProcessing = null;

    /**
     * @return string
     */
    public function getUrl(): string
    {
        return $this->url;
    }

    /**
     * @param string $url
     * @return RequestResultBean
     */
    public function setUrl(string $url): self
    {
        $this->url = $url;
        return $this;
    }

    /**
     * @return string
     */
    public function getMethod(): string
    {
        return $this->method;
    }

    /**
     * @param string $method
     * @return RequestResultBean
     */
    public function setMethod(string $method): self
    {
        $this->method = $method;
        return $this;
    }

    /**
     * @return array|string
     */
    public function getRequest(): array|string
    {
        return $this->request;
    }

    /**
     * @param array|string $request
     * @return RequestResultBean
     */
    public function setRequest(array|string $request): self
    {
        $this->request = $request;
        return $this;
    }

    /**
     * @return string|false
     */
    public function getResponse(): bool|string
    {
        return $this->response;
    }

    /**
     * @param bool|string $response
     * @return RequestResultBean
     */
    public function setResponse(bool|string $response): self
    {
        $this->response = $response;
        $this->setSendApi(true);
        return $this;
    }

    /**
     * @return array
     */
    public function getOptions(): array
    {
        return $this->options;
    }

    /**
     * @param array $options
     * @return RequestResultBean
     */
    public function setOptions(array $options): self
    {
        $this->options = $options;
        return $this;
    }

    /**
     * @return bool
     */
    public function isResult(): bool
    {
        return $this->result;
    }

    /**
     * @param bool $result
     * @return RequestResultBean
     */
    public function setResult(bool $result): self
    {
        $this->result = $result;
        return $this;
    }

    /**
     * @return string
     */
    public function getErrorMessage(): string
    {
        return $this->errorMessage;
    }

    /**
     * @param string $errorMessage
     * @return static
     */
    public function setErrorMessage(string $errorMessage): static
    {
        $this->errorMessage = $errorMessage;
        return $this;
    }

    /**
     * @return array
     */
    public function getFormatResponse(): array
    {
        return $this->formatResponse;
    }

    /**
     * @param array $formatResponse
     */
    public function setFormatResponse(array $formatResponse): void
    {
        $this->formatResponse = $formatResponse;
    }

    /**
     * @return bool
     */
    public function isSendApi(): bool
    {
        return $this->sendApi;
    }

    /**
     * @param bool $sendApi
     */
    public function setSendApi(bool $sendApi): void
    {
        $this->sendApi = $sendApi;
    }

    /**
     * @return callable|null
     */
    public function getApiSynchronousEndProcessing(): ?callable
    {
        return $this->apiSynchronousEndProcessing;
    }

    /**
     * @param callable $apiSynchronousEndProcessing
     * @return $this
     */
    public function setApiSynchronousEndProcessing(callable $apiSynchronousEndProcessing): self
    {
        $this->apiSynchronousEndProcessing = $apiSynchronousEndProcessing;
        return $this;
    }


}
